import request from '@/utils/request'
import store from '@/store'
//const ascriptionId = store.state.userInfo.ascriptionId;
// 资讯管理

// 页面内容 左侧树 资讯分类
export function getPage(queryParams) {
    const data = {
        ascriptionId: store.state.userInfo.ascriptionId,
        currentPage: queryParams.currentPage,
        pagesize: queryParams.pagesize
    }
    return request({
      url: '/getNewsPage',
      method: 'post',
      data: data
    })
}

// 数据列表
export function listData(queryParams) {
    const data = {
      ascriptionId: store.state.userInfo.ascriptionId,
      currentPage: queryParams.currentPage,
      pagesize: queryParams.pagesize,
      keywords: queryParams.keywords,
      category: queryParams.category, //资讯分类id
      startTime: queryParams.startTime, //发布时间 开始时间
      endTime: queryParams.endTime, //发布时间 结束时间
    }
    return request({
      url: '/getNewsList',
      method: 'post',
      data: data
    })
}

// 新增
export function addData(val) {
  const data = {
    projectContent:{
        ascriptionId: store.state.userInfo.ascriptionId, //机构 id
        categoryId: val.categoryId, //资讯分类id
        category: val.category, //资讯分类
        title: val.title, //标题
        content: val.content, //内容
        thePic: val.thePic, //相关配图
        topping: val.topping, //是否置顶 0-不置顶 1-置顶
        reviewerLevel: val.reviewerLevel, //发布级别 0-部门发布 1-人员发布
        departmentId: val.departmentId, //发布部门 id
        department: val.department, //发布部门
        reviewerId: val.reviewerId, //发布人id
        reviewer: val.reviewer, //发布人
        reviewTime: val.reviewTime, //发布时间
        source: val.source, //信息来源
        theLink: val.theLink, //附件
        sort: val.sort //位置排序
    }
  }
  return request({
    url: '/addNews',
    method: 'post',
    data: data
  })
}

// 获取单条数据
export function getData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getNewsData',
    method: 'post',
    data: data
  })
}

// 修改
export function updateData(val) {
  const data = {
    projectContent:{
        theid: val.theid, //id
        categoryId: val.categoryId, //资讯分类id
        category: val.category, //资讯分类
        title: val.title, //标题
        content: val.content, //内容
        thePic: val.thePic, //相关配图
        topping: val.topping, //是否置顶 0-不置顶 1-置顶
        reviewerLevel: val.reviewerLevel, //发布级别 0-部门发布 1-人员发布
        departmentId: val.departmentId, //发布部门 id
        department: val.department, //发布部门
        reviewerId: val.reviewerId, //发布人id
        reviewer: val.reviewer, //发布人
        reviewTime: val.reviewTime, //发布时间
        source: val.source, //信息来源
        theLink: val.theLink, //附件
        sort: val.sort //位置排序
    }
  }
  return request({
    url: '/updateNews',
    method: 'post',
    data: data
  })
}

// 删除
export function delData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/delNews',
    method: 'post',
    data: data
  })
}

// 批量删除   idListStr id列表  逗号隔开
export function delMultiData(idListStr) {
  const data = {
    idListStr
  }
  return request({
    url: '/delMultipleNews',
    method: 'post',
    data: data
  })
}
